package revokeroledii;

import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;


public class RevokeRoleDIIClient {
    private static String qnameService = "RevokeRoleService";
    private static String qnamePort = "RevokeRoleIF";
    private static String BODY_NAMESPACE_VALUE = "urn:Foo";
    private static String ENCODING_STYLE_PROPERTY =
        "javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD = "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING =
        "http://schemas.xmlsoap.org/soap/encoding/";

    public static void main(String[] args) {
    	//set Endpoint address
    	String endpointAddr = "http://localhost:8080/RSSRevokeRole/revoke";
        System.out.println("###Endpoint address = " + endpointAddr);

        try {
            ServiceFactory factory = ServiceFactory.newInstance();
            Service service = factory.createService(new QName(qnameService));

            QName port = new QName(qnamePort);

            Call call = service.createCall(port);

            call.setTargetEndpointAddress(endpointAddr);
            call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
            call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
            call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);

            QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
            QName QNAME_TYPE_BOOLEAN = new QName(NS_XSD, "boolean");
            QName QNAME_TYPE_INT = new QName(NS_XSD, "int");
    
            //set return type
            call.setReturnType(QNAME_TYPE_BOOLEAN);
            
            //set operation name
            call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "revokeRole"));
            
            //set parameters
            call.addParameter("int_1", QNAME_TYPE_INT, ParameterMode.IN);
            call.addParameter("String_2", QNAME_TYPE_STRING, ParameterMode.IN);
            call.addParameter("String_3", QNAME_TYPE_STRING, ParameterMode.IN);


            //construct parameters
            int comId = Integer.parseInt(args[0]);
            Object[] params = {comId, args[1], args[2] };

            boolean result = (Boolean) call.invoke(params );

            System.out.println(result);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
